import Vue from 'vue'
import Vuex from 'vuex'

import { setItem, getItem, removeItem } from '@/utils/storage.js'

Vue.use(Vuex)

const TOUTIAO_USER = 'TOUTIAO_USER'
export default new Vuex.Store({
  state: {
    // 用户的登录状态信息
    user: getItem(TOUTIAO_USER),
    // user: null
  },
  mutations: {
    setUser(state, user) {
      //将登录返回的token data同步到vuex
      state.user = user
      setItem(TOUTIAO_USER, user)
    },
    removeUser(state) {
      state.user = ''
      removeItem(TOUTIAO_USER)
    },
  },
  actions: {
  },
  modules: {
  }
})
